#ifndef FRACTION
#define FRACTION
#include <iostream>

using namespace std;

// 求最大公约数
int gcd(int a, int b)
{
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}

class Fraction
{
private:
    int numerator;   // 分子
    int denominator; // 分母

public:
    Fraction()
    {
        numerator = 0;
        denominator = 1;
    }
    Fraction(const int _a)
    {
        numerator = _a;
        denominator = 1;
    }
    Fraction(const Fraction &rhs)
    {
        numerator = rhs.numerator;
        denominator = rhs.denominator;
    }

    Fraction(int n, int d) : numerator(n), denominator(d)
    {
        // 分数约分
        int g = gcd(numerator, denominator);
        numerator /= g;
        denominator /= g;
    }

    Fraction operator=(const Fraction &f)
    {
        numerator = f.numerator;
        denominator = f.denominator;
        return *this;
    }

    // 加法运算
    Fraction operator+(const Fraction &f) const
    {
        int n = numerator * f.denominator + f.numerator * denominator;
        int d = denominator * f.denominator;
        return Fraction(n, d);
    }

    // 减法运算
    Fraction operator-(const Fraction &f) const
    {
        int n = numerator * f.denominator - f.numerator * denominator;
        int d = denominator * f.denominator;
        return Fraction(n, d);
    }

    // 乘法运算
    Fraction operator*(const Fraction &f) const
    {
        int n = numerator * f.numerator;
        int d = denominator * f.denominator;
        return Fraction(n, d);
    }

    // 除法运算
    Fraction operator/(const Fraction &f) const
    {
        int n = numerator * f.denominator;
        int d = denominator * f.numerator;
        return Fraction(n, d);
    }

    Fraction operator+=(const Fraction &f)
    {
        return (*this) = (*this) + f;
    }

    Fraction operator-=(const Fraction &f)
    {
        return (*this) = (*this) - f;
    }

    Fraction operator*=(const Fraction &f)
    {
        return (*this) = (*this) * f;
    }

    Fraction operator/=(const Fraction &f)
    {
        return (*this) = (*this) / f;
    }

    // 将分数转换为 double 类型
    double todouble()
    {
        return (double)numerator / denominator;
    }

    // 输出分数
    friend ostream &operator<<(ostream &os, const Fraction &f)
    {
        if (f.numerator == 0)
            os << 0;
        else if (f.denominator == 1)
            os << f.numerator;
        else
            os << f.numerator << "/" << f.denominator;
        return os;
    }
};
#endif